package com.jeegit.ecms.service.impl;

import java.util.List;
import java.util.ArrayList;
import com.jeegit.common.core.domain.Ztree;
import com.jeegit.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.jeegit.ecms.mapper.CmsBannerCategoryMapper;
import com.jeegit.ecms.domain.CmsBannerCategory;
import com.jeegit.ecms.service.ICmsBannerCategoryService;
import com.jeegit.common.core.text.Convert;

/**
 * 横幅图片Service业务层处理
 * 
 * @author jeegit
 * @date 2022-06-25
 */
@Service
public class CmsBannerCategoryServiceImpl implements ICmsBannerCategoryService 
{
    @Autowired
    private CmsBannerCategoryMapper cmsBannerCategoryMapper;

    /**
     * 查询横幅图片
     * 
     * @param id 横幅图片主键
     * @return 横幅图片
     */
    @Override
    public CmsBannerCategory selectCmsBannerCategoryById(Long id)
    {
        return cmsBannerCategoryMapper.selectCmsBannerCategoryById(id);
    }

    /**
     * 查询横幅图片列表
     * 
     * @param cmsBannerCategory 横幅图片
     * @return 横幅图片
     */
    @Override
    public List<CmsBannerCategory> selectCmsBannerCategoryList(CmsBannerCategory cmsBannerCategory)
    {
        return cmsBannerCategoryMapper.selectCmsBannerCategoryList(cmsBannerCategory);
    }

    /**
     * 新增横幅图片
     * 
     * @param cmsBannerCategory 横幅图片
     * @return 结果
     */
    @Override
    public int insertCmsBannerCategory(CmsBannerCategory cmsBannerCategory)
    {
        cmsBannerCategory.setCreateTime(DateUtils.getNowDate());
        return cmsBannerCategoryMapper.insertCmsBannerCategory(cmsBannerCategory);
    }

    /**
     * 修改横幅图片
     * 
     * @param cmsBannerCategory 横幅图片
     * @return 结果
     */
    @Override
    public int updateCmsBannerCategory(CmsBannerCategory cmsBannerCategory)
    {
        cmsBannerCategory.setUpdateTime(DateUtils.getNowDate());
        return cmsBannerCategoryMapper.updateCmsBannerCategory(cmsBannerCategory);
    }

    /**
     * 批量删除横幅图片
     * 
     * @param ids 需要删除的横幅图片主键
     * @return 结果
     */
    @Override
    public int deleteCmsBannerCategoryByIds(String ids)
    {
        return cmsBannerCategoryMapper.deleteCmsBannerCategoryByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除横幅图片信息
     * 
     * @param id 横幅图片主键
     * @return 结果
     */
    @Override
    public int deleteCmsBannerCategoryById(Long id)
    {
        return cmsBannerCategoryMapper.deleteCmsBannerCategoryById(id);
    }

    /**
     * 查询横幅图片树列表
     * 
     * @return 所有横幅图片信息
     */
    @Override
    public List<Ztree> selectCmsBannerCategoryTree()
    {
        List<CmsBannerCategory> cmsBannerCategoryList = cmsBannerCategoryMapper.selectCmsBannerCategoryList(new CmsBannerCategory());
        List<Ztree> ztrees = new ArrayList<Ztree>();
        for (CmsBannerCategory cmsBannerCategory : cmsBannerCategoryList)
        {
            Ztree ztree = new Ztree();
            ztree.setId(cmsBannerCategory.getId());
            ztree.setpId(cmsBannerCategory.getParentId());
            ztree.setName(cmsBannerCategory.getTitle());
            ztree.setTitle(cmsBannerCategory.getTitle());
            ztrees.add(ztree);
        }
        return ztrees;
    }
}
